layui.define(function(exports) {
	
    var getBtn = function(btns,isIcon,hideType){
        var btnHtml = '' ;
        var btnActions = window.__action__  || '00';
        var administrator = true;
        btns.map(function(h){
            var btnClass="layui-btn layui-btn-normal layui-btn-sm ";
            if(h.show===false || h.show==="false" || h.show=="0" || h.show=="3"){
            	btnClass += (hideType || "hide");
            }
            if(h.btns && h.btns[0] && (String(btnActions).indexOf(h.action || "00") != -1 || administrator)){
                var dds = "";
                h.btns.map(function(val){
                    if(String(btnActions).indexOf(val.action || "00") != -1 || administrator){
                        dds += `
	                        <dd  ${val.id? "id="+val.id  : '' } onClick="${val.onClick}">
	                            <a href="javascript:void(0);">${val.title}</a>
	                        </dd>`;
                    }
                });
                if(dds){
                	btnHtml += `
	                    <button type="button" class="${btnClass} btnMore" ${h.id? "id="+h.id  : '' } >
	                        ${h.title} <i class="iconfont" style="line-height: 0;">&#xe604;</i> 
	                        <dl class="layui-nav-child">${dds}</dl>
	                    </button>
	                `;
                }
            }else if(String(btnActions).indexOf(h.action || "00") != -1 || administrator){
                btnHtml += `
                    <button type="button" class="${btnClass}"  ${h.id? "id="+h.id  : '' } 
                    	onClick="${h.onClick}"
                    	on-click="${h['on-click'] || ''}"
                    	style="background:${h['bgColor'] || ''};"
                    >
                        <i class="iconfont" style="line-height: 0;">${getIcon(h.title,isIcon)}</i>${h.title}
                    </button>
                `;
            }
        });
        return $.removeTrimEnter(btnHtml);
    }
    
    //判断图标
    var getIcon=function(title,isIcon){
        if(isIcon===false){
            return "";
        }else if(title.indexOf('增' )!=-1 || title.indexOf('加' ) !=-1 || title.indexOf('添' ) !=-1){
            return "&#xe6af;";
        }else if(title.indexOf('删除' )!=-1 || title.indexOf('清空' )!=-1){
            return "&#xe68e;";
        }else if(title.indexOf('编辑' )!=-1 || title.indexOf('修改' )!=-1 || title.indexOf('更新' )!=-1){
            return "&#xe617;";
        }else if(title.indexOf('同步' )!=-1 ){
            return "&#xe6e2;";
        }else if(title.indexOf('地图' )!=-1 || title.indexOf('位置' )!=-1 || title.indexOf('标记' )!=-1){
            return "&#xe62b;";
        }else if(title.indexOf('搜' )!=-1 || title.indexOf('查' )!=-1){
            return "&#xe651;";
        }else if(title.indexOf('入' )!=-1){
            return "&#xe73d;";
        }else if(title.indexOf('出' )!=-1){
            return "&#xe70d;";
        }else if(title.indexOf('绑' )!=-1){
            return "&#xe631;";
        }else if(title.indexOf('确定' )!=-1 || title.indexOf('保存' )!=-1 || title.indexOf('确认' )!=-1){
            return "&#xe80c;";
        }else if(title.indexOf('申请' )!=-1 || title.indexOf('申报' )!=-1  || title.indexOf('预约' )!=-1){
            return "&#xe66a;";
        }else if(title.indexOf('审核' )!=-1 || title.indexOf('审批')!=-1){
            return "&#xe633;";
        }else if(title.indexOf('刷新' )!=-1){
            return "&#xe60c;";
        }else if(title.indexOf('授权' )!=-1){
            return "&#xe6dd;";
        }else if(title.indexOf('禁' )!=-1){
            return "&#xe645;";
        }else if(title.indexOf('获取' )!=-1){
            return "&#xe646;";
        }else if(title.indexOf('重置' )!=-1){
            return "&#xe6bf;";
        }else if(title.indexOf('返回' )!=-1){
            return "&#xe649;";
        }else{
            return "&#xe622;";
        }
    }
    
    exports('button',{getBtn:getBtn});
});